{include file="common:header" /}

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 数据表格 -->
            <table id="adminTable" lay-filter="adminTable"></table>
        </div>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="userTbBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="addAdminTbBar">
    <a class="layui-btn layui-btn-sm" lay-event="add">添加</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="roster">排班</a>-->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="roleEditDialog">
    <form id="roleEditForm" lay-filter="roleEditForm" class="layui-form model-form no-padding">
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="userEditSubmit" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>
<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        /* 渲染表格 */
        var insTb = table.render({
            elem: '#adminTable',
            id: 'adminTable_id',
            url: "{:url('api')}",
            defaultToolbar: [],
            page: true,
            limit: 20,
            limits: [15,20,30],
            height: 'full-50',
            toolbar: "#addAdminTbBar",
            cellMinWidth: 100,
            cols: [[
                {type:'numbers', title: '编号'},
                {field: 'id', title: '编号', sort: true},
                {field: 'username', title: '用户名', sort: true},
                {field: 'phone', title: '手机号'},
                {field: 'create_time', title: '创建时间', sort: true},
                // {field: 'state', title: '状态', templet: '#userTbState', sort: true, width: 100},
                {title: '操作', toolbar: '#userTbBar', align: 'center', minWidth: 200}
            ]]
        });

        /* 表格工具条点击事件 */
        table.on('tool(adminTable)', function (obj) {
            if (obj.event === 'edit') { // 修改
                edit(obj.data.id);
            } else if (obj.event === 'del') { // 删除
                doDel(obj.data.id);
            }
        });

        /* 表格头工具栏点击事件 */
        table.on('toolbar(adminTable)', function (obj) {
            if (obj.event === 'add') { // 添加
                create();
            }
        });
        /* 显示表单弹窗 */
        function create() {
            admin.open({
                title: '员工信息 — 新增',
                type: 2,
                area:'750px',
                isOutAnim :false,
                url: "{:url('create')}"
            });
        }
        /* 显示表单弹窗 */
        function edit(id) {
            admin.open({
                title: '员工信息 — 编辑',
                type: 2,
                area:'750px',
                isOutAnim :false,
                url: "{:url('edit')}" + '?id=' + id
            });
        }
        /* 删除 */
        function doDel(id) {
            layer.confirm('确定要删除选中数据吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                var loadIndex = layer.load(4);
                $.get("{:url('delete')}", {id: id}, function (res) {
                    layer.close(loadIndex);
                    layer.msg(res.msg);
                    if (res.code === 1) {
                        insTb.reload({page: {curr: 1}});
                    }
                }, 'json');
            });
        }
    });
</script>
</body>
</html>
